home *** CD-ROM | disk | FTP | other *** search
- Attribute VB_Name = "modTimer"
- Option Explicit
- '-------------------------------------------------------------------------
- 'modTimer is a support module for clsTimer
- '-------------------------------------------------------------------------
-
- Declare Function SetTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
- Declare Function KillTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long) As Long
-
- Public gcTimerObjects As Collection 'Timer object that are instanciated WithEvents
- 'Add themselves to this collection when they need
- 'to start a timer. Set Timer returns a TimerID which
- 'the timer object converts to a string and uses as a key
- 'when it adds itself to the collection. The Callback
- 'function converst the passed TimerID to a string
- 'and uses it as a key to this collection.
-
- Public Sub TimerProc(ByVal lHwnd As Long, ByVal lMsg As Long, ByVal lTimerID As Long, ByVal lTime As Long)
- '-------------------------------------------------------------------------
- 'Purpose: Address of this function is passed in the SetTimer API. When
- ' a system timer is started it calls this function every set
- ' interval
- 'In: [lTimerID]
- ' Equals the return value of the SetTimer API. It basically identifies
- ' what system timer called this function so that I can trigger a
- ' raise event in the Timer object that started the calling
- ' system timer.
- 'Effects: Finds a clsTimerLink class object in the gcTimerObjects collection
- ' whose key matches the lTimerID parameter. Calls the RaiseTick
- ' method on the found object.
- '-------------------------------------------------------------------------
- Dim oTimerObject As clsTimerLink
- On Error Resume Next 'Error handling because TimerProc
- 'can be called after objects
- 'are destroyed
- Set oTimerObject = gcTimerObjects.Item(Str$(lTimerID))
- oTimerObject.RaiseTick
- End Sub
-
- Public Function StartTimer(lInterval As Long) As Long
- '-------------------------------------------------------------------------
- 'Purpose: Starts a system timer
- 'In: [lInterval]
- ' The interval in milliseconds for the desired timer
- 'Effects: Calls the SetTimer API, passing the AddressOF the TimerProc
- ' Function and lInterval
- '-------------------------------------------------------------------------
- StartTimer = SetTimer(0, 0, lInterval, AddressOf TimerProc)
- End Function
-
- Public Function StopTimer(lTimerID As Long) As Long
- '-------------------------------------------------------------------------
- 'Purpose: Stops a specific system timer
- 'In: [lTimerID]
- ' The ID of the specific system timer to stop
- 'Effects: Calls the KillTimerID API, passing lTimerID
- '-------------------------------------------------------------------------
- StopTimer = KillTimer(0, lTimerID)
- End Function
-
- Public Sub SetInterval(lInterval As Long, lTimerID As Long)
- '-------------------------------------------------------------------------
- 'Purpose: Changes the interval of an alreading existing system timer
- 'In: [lTimerID]
- ' The ID of the specific system timer to change
- ' [lInterval]
- ' The interval to change the timer to.
- 'Effects: Calls the SetTimer API, passing lTimerID, lInterval, and the
- ' AddressOf TimerProc
- '-------------------------------------------------------------------------
- Dim lResult As Long
- lResult = SetTimer(0, lTimerID, lInterval, AddressOf TimerProc)
- End Sub
-
-